package com.practice.线程池;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;
@Slf4j
public class ThreadPool {
    private static ExecutorService pool;

    public static void main( String[] args ) {
        //maximumPoolSize设置为2 ，拒绝策略为AbortPolic策略，直接抛出异常
        pool = new ThreadPoolExecutor(1, 2, 1000, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
        for(int i=0;i<3;i++) {
            pool.execute(()->{
                System.out.println(Thread.currentThread().getName());
                log.info(Thread.currentThread().getName());
            });
        }
    }

}

